/*
 * @Author: 'YSJ' '951866543@qq.com'
 * @Date: 2024-09-11 14:51:48
 * @LastEditors: 'YSJ' '951866543@qq.com'
 * @LastEditTime: 2024-09-11 14:51:55
 * @FilePath: \smart-subway\src\cesiumTools\core.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
//计算每个点位时间与总时间
// pArr:[{x,y,z}]
// speed number
export const getSiteTimes = (pArr, speed) => {
  let timeSum = 0,
    times = []
  for (var i = 0; i < pArr.length; i++) {
    if (i == 0) {
      times.push(0) //第0个时间为0
      continue
    }

    // 计算总时间
    timeSum += spaceDistance([pArr[i - 1], pArr[i]]) / speed
    // 将每段距离所用的时间收集起来
    times.push(timeSum)
  }
  return {
    timeSum: timeSum,
    siteTimes: times,
  }
}

//计算距离
export const spaceDistance = (positions) => {
  let distance = 0
  for (let i = 0; i < positions.length - 1; i++) {
    let s = Cesium.Cartesian3.distance(positions[i], positions[i + 1])
    distance = distance + s
  }
  return distance.toFixed(2)
}
